home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / DirectShow_WinXP / VMR / VMRXcl / d3dfont.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-08  |  2.9 KB  |  107 lines

  1. //-----------------------------------------------------------------------------
  2. // File: D3DFont.h
  3. //
  4. // Desc: Texture-based font class
  5. //
  6. // Copyright (c) 2000-2001 Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #ifndef D3DFONT_H
  9. #define D3DFONT_H
  10. #include <tchar.h>
  11. #include <ddraw.h>
  12. #include <d3dxmath.h>
  13. #define D3D_OVERLOADS
  14. #include <d3d.h>
  15.  
  16.  
  17. // Font creation flags
  18. #define D3DFONT_BOLD        0x0001
  19. #define D3DFONT_ITALIC      0x0002
  20.  
  21. // Font rendering flags
  22. #define D3DFONT_CENTERED    0x0001
  23. #define D3DFONT_TWOSIDED    0x0002
  24. #define D3DFONT_FILTERED    0x0004
  25.  
  26.  
  27. #ifndef __INITDDSTRUCT_DEFINED
  28. #define __INITDDSTRUCT_DEFINED
  29. template <typename T>
  30. __inline void INITDDSTRUCT(T& dd)
  31. {
  32.     ZeroMemory(&dd, sizeof(dd));
  33.     dd.dwSize = sizeof(dd);
  34. }
  35. #endif
  36.  
  37. #ifndef __RELEASE_DEFINED
  38. #define __RELEASE_DEFINED
  39. template<typename T>
  40. __inline void RELEASE( T* &p )
  41. {
  42.     if( p ) {
  43.         p->Release();
  44.         p = NULL;
  45.     }
  46. }
  47. #endif
  48.  
  49.  
  50. #define MAX_NUM_VERTICES 50*6
  51.  
  52. //-----------------------------------------------------------------------------
  53. // Custom vertex types for rendering text
  54. //-----------------------------------------------------------------------------
  55. struct FONT2DVERTEX {
  56.     D3DXVECTOR4 p;
  57.     DWORD color;
  58.     FLOAT tu, tv;
  59. };
  60.  
  61.  
  62. //-----------------------------------------------------------------------------
  63. // Name: class CD3DFont
  64. // Desc: Texture-based font class for doing text in a 3D scene.
  65. //-----------------------------------------------------------------------------
  66. class CD3DFont
  67. {
  68.     TCHAR   m_strFontName[80];            // Font properties
  69.     DWORD   m_dwFontHeight;
  70.     DWORD   m_dwFontFlags;
  71.  
  72.     LPDIRECT3DDEVICE7       m_pd3dDevice; // A D3DDevice used for rendering
  73.     LPDIRECTDRAWSURFACE7    m_pTexture;   // The d3d texture for this font
  74.     FONT2DVERTEX            m_VB[MAX_NUM_VERTICES];  // VertexBuffer for rendering text
  75.  
  76.     DWORD   m_dwTexWidth;                 // Texture dimensions
  77.     DWORD   m_dwTexHeight;
  78.     FLOAT   m_fTextScale;
  79.     FLOAT   m_fTexCoords[128-32][4];
  80.  
  81.     // Stateblocks for setting and restoring render states
  82.     DWORD   m_dwSavedStateBlock;
  83.     DWORD   m_dwDrawTextStateBlock;
  84.  
  85. public:
  86.     // 2D and 3D text drawing functions
  87.     HRESULT DrawText( FLOAT x, FLOAT y, DWORD dwColor,
  88.                       TCHAR* strText, DWORD dwFlags=0L );
  89.  
  90.     // Function to get extent of text
  91.     HRESULT GetTextExtent( TCHAR* strText, SIZE* pSize );
  92.  
  93.     // Initializing and destroying device-dependent objects
  94.     HRESULT InitDeviceObjects(LPDIRECTDRAW7 pDD, LPDIRECT3DDEVICE7 pd3dDevice);
  95.     HRESULT RestoreDeviceObjects();
  96.     HRESULT InvalidateDeviceObjects();
  97.     HRESULT DeleteDeviceObjects();
  98.  
  99.     // Constructor / destructor
  100.     CD3DFont( TCHAR* strFontName, DWORD dwHeight, DWORD dwFlags=0L );
  101.     ~CD3DFont();
  102. };
  103.  
  104. #endif
  105.  
  106.  
  107.